package com.koron.css2.serviceManage.mapper;

import com.koron.css2.baseConfig.bean.MatrCodeBean;
import com.koron.css2.baseConfig.vo.MatrSelectVO;
import com.koron.css2.serviceManage.queryBean.matrCodeQueryBean;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.koron.ebs.mybatis.EnvSource;

import java.util.List;

@EnvSource("_default")
public interface MatrCodeMapper {

    /**
     * 查询列表
     *
     * @return
     */
    List<MatrCodeBean> selectMatrCodeList(matrCodeQueryBean bean);

    /**
     *根据物料id查询物料信息
     * @param matrId
     * @return
     */
    @Select("select * from PUB_MATR_CODE where id =#{matrId}")
    MatrCodeBean selectMatrCodeById(@Param("matrId") String matrId);

    /**
     * 添加
     *
     * @param matrTemplateBean
     * @return
     */
    void insertMatrCode(MatrCodeBean matrTemplateBean);

    /**
     * 校验字段内容重复
     */
    @Select("select count(*) from PUB_MATR_CODE where ${key} = #{val}")
    Integer check(@Param("key") String key, @Param("val") String val);

    /**
     * 校验字段内容重复-排除当前记录
     */
    @Select("select count(*) from PUB_MATR_CODE where ${key} = #{val} and id <> #{id}")
    Integer check2(@Param("key") String key, @Param("val") String val, @Param("id") String id);


    /**
     * 修改
     *
     * @param matrTemplateBean
     * @return
     */
    Integer updateMatrCode(MatrCodeBean matrTemplateBean);

    @Select("select id,matr_no,matr_name,matr_mode,matr_num,matr_unit,matr_price from PUB_MATR_CODE")
    List<MatrSelectVO> matrSelect();

    @Select("select * from PUB_MATR_CODE " +
            "where matr_no = #{matrNo}")
    MatrCodeBean selectMatrTemplateByNo(@Param("matrNo") String matrNo);

    @Select("select * from PUB_MATR_CODE where id = #{parentId}")
    MatrCodeBean findMatrCodeById(@Param("parentId") String parentId);

    @Select("select max(class_code) maxCode  from PUB_MATR_CODE where class_code like CONCAT(#{parentClassCode},'_____')")
    String findMaxChild(@Param("parentClassCode") String parentClassCode);

    List<MatrCodeBean> getMatrCodeList(matrCodeQueryBean selectBean);
}
